<!DOCTYPE html>
<html>
<head>
  <title>九宫格</title>
  <style type="text/css" media="screen">
    *{
      margin: 0;
      padding: 0;
    }
    .grid{
      display: flex;
      width: 300px;
      flex-wrap: wrap;
      list-style: none;
      padding: 50px;
    }    
    .grid li{
      width: 100px;
      height: 100px;
      line-height: 100px;
      text-align: center;
      border: 4px solid #ccc;
      box-sizing: border-box;
      margin-top: -4px;
      margin-left: -4px;
    }
    .grid li:nth-child(3n+1){
      margin-left: 0px;
    }
    .grid li:hover{
      border-color: red;
      z-index:2;
    }
  </style>  
</head>
<body>
  <ul class="grid">
    <li>1</li>
    <li>2</li>
    <li>3</li>
    <li>4</li>
    <li>5</li>
    <li>6</li>
    <li>7</li>
    <li>8</li>
    <li>9</li>
  </ul>
</body>
</html>